﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace PFAGame
{
    class MeleeRobot : AMob
    {
        public const int COUNT_INSTANCE = 20;
        static SoundEffect sound;
        public static SoundEffectInstance[] soundInstance;
        public static int n = 0;

        public MeleeRobot(float x, float y)
        {
            position.X = x;
            position.Y = y;
            type = e_typeMob.MELEE;

            moveRightAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobCAC/MobCACRunSide"), 503, 504, 2, (int)(100 / speed), true);
            moveLeftAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobCAC/MobCACRunSide2"), 503, 504, 2, (int)(100 / speed), true);
            moveUpAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobCAC/MobCACRunFront"), 503, 504, 2, (int)(100 / speed), true);
            moveDownAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobCAC/MobCACRunBack"), 503, 504, 2, (int)(100 / speed), true);

            attackRightAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobCAC/MobCACHitSide"), 503, 504, 3, (int)(30 * speed), false);
            attackLeftAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobCAC/MobCACHitSide2"), 503, 504, 3, (int)(30 * speed), false);
            attackUpAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobCAC/MobCACHitFront"), 503, 504, 3, (int)(30 * speed), false);
            attackDownAnim.Initialize(ScreenManager.Singleton.Game.Content.Load<Texture2D>("Images/Mob/MobCAC/MobCACHitBack"), 503, 504, 3, (int)(30 * speed), false);

            if (sound == null)
            {
                sound = ScreenManager.Singleton.Game.Content.Load<SoundEffect>("Sound_effects/swort_hit");
                soundInstance = new SoundEffectInstance[COUNT_INSTANCE];
                for (int i = 0; i < COUNT_INSTANCE; i++)
                {
                    soundInstance[i] = sound.CreateInstance();
                    soundInstance[i].Volume = 0.2f;
                    soundInstance[i].IsLooped = false;
                }
            }
        }

        protected override void attack()
        {
            //inflige les dégats, si la cibles est toujours à porté
            if (target.getSquaredDistance(position) <= range * range)
                target.receiveDammage(dammage);

            soundInstance[n++].Play();
            if (n >= COUNT_INSTANCE)
                n = 0;
        }

        public override void init()
        {
            base.init();
            dammage = 10;
            speed = 2.2f;
        }
    }
}
